package com.ruoyi.web.controller.mall;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mall.domain.BizClassify;
import com.ruoyi.mall.service.IBizClassifyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * 商城类目Controller
 * 
 * @author WeiHuan.Li
 * @date 2024-04-29
 */
@RestController
@RequestMapping("/mall/classify")
public class BizClassifyController extends BaseController
{
    @Autowired
    private IBizClassifyService bizClassifyService;

    /**
     * 查询商城类目列表
     */
    @PreAuthorize("@ss.hasPermi('mall:classify:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizClassify bizClassify)
    {
        startPage();
        List<BizClassify> list = bizClassifyService.selectBizClassifyList(bizClassify);
        return getDataTable(list);
    }

    /**
     * 导出商城类目列表
     */
    @PreAuthorize("@ss.hasPermi('mall:classify:export')")
    @Log(title = "商城类目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizClassify bizClassify)
    {
        List<BizClassify> list = bizClassifyService.selectBizClassifyList(bizClassify);
        ExcelUtil<BizClassify> util = new ExcelUtil<BizClassify>(BizClassify.class);
        util.exportExcel(response, list, "商城类目数据");
    }

    /**
     * 获取商城类目详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:classify:query')")
    @GetMapping(value = "/{classifyId}")
    public AjaxResult getInfo(@PathVariable("classifyId") Long classifyId)
    {
        return success(bizClassifyService.selectBizClassifyByClassifyId(classifyId));
    }

    /**
     * 新增商城类目
     */
    @PreAuthorize("@ss.hasPermi('mall:classify:add')")
    @Log(title = "商城类目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizClassify bizClassify)
    {
        bizClassify.setCreateBy(getUsername());
        return toAjax(bizClassifyService.insertBizClassify(bizClassify));
    }

    /**
     * 修改商城类目
     */
    @PreAuthorize("@ss.hasPermi('mall:classify:edit')")
    @Log(title = "商城类目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizClassify bizClassify)
    {
        bizClassify.setUpdateBy(getUsername());

        return toAjax(bizClassifyService.updateBizClassify(bizClassify));
    }

    /**
     * 禁用-启用
     * @param bizClassify
     * @return
     */
    @PreAuthorize("@ss.hasPermi('mall:classify:edit')")
    @Log(title = "启用-禁用", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody BizClassify bizClassify)
    {
        bizClassify.setUpdateBy(getUsername());
        return toAjax(bizClassifyService.updateBizClassifyStatus(bizClassify));
    }
    /**
     * 删除商城类目
     */
    @PreAuthorize("@ss.hasPermi('mall:classify:remove')")
    @Log(title = "商城类目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classifyIds}")
    public AjaxResult remove(@PathVariable Long[] classifyIds)
    {
        return toAjax(bizClassifyService.deleteBizClassifyByClassifyIds(classifyIds));
    }
}
